<template>
  <div class="registerbox">
    <el-card class="gray-card no-border no-margin-top" shadow="never">
      <el-form ref="form" :model="form" class="form">
        <el-form-item label="仪器编码：">
          <el-select v-model="form.instrumentId" placeholder="请选择" maxlength="100" show-word-limit>
            <el-option
              v-for="dict in instrumentOptions"
              :key="dict.id"
              :label="dict.instrumentName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="校验项目：">
          <el-select v-model="form.projectId" placeholder="请选择">
            <el-option
              v-for="dict in projectOptions"
              :key="dict.id"
              :label="dict.projectName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="质控品批次：">
          <el-input placeholder="质控品批次"
                    v-model="form.materialBatchNo"
          >>
          </el-input>
          <!--                <el-select v-model="form.materialBatchNo" placeholder="请选择" >-->
          <!--                    <el-option-->
          <!--                        v-for="item in dateOptions"-->
          <!--                        :key="item.value"-->
          <!--                        :label="item.label"-->
          <!--                        :value="item.value">-->
          <!--                    </el-option>-->
          <!--                </el-select>-->
        </el-form-item>
        <el-form-item label="试剂批号：">
          <!--                <el-select v-model="form.reagentBatchNo" placeholder="请选择" >-->
          <!--                    <el-option-->
          <!--                        v-for="item in dateOptions"-->
          <!--                        :key="item.value"-->
          <!--                        :label="item.label"-->
          <!--                        :value="item.value">-->
          <!--                    </el-option>-->
          <!--                </el-select>-->
          <el-input placeholder="试剂批号"
                    v-model="form.reagentBatchNo"
          >>
          </el-input>
        </el-form-item>

      </el-form>
    </el-card>
    <div class="details-foot">
      <div class="cell-btn">
        <el-button type="primary" @click="onSubmit()">立即创建</el-button>
        <el-button  @click="toBack()">取消</el-button>
      </div>
    </div><!------details-foot 底部预警------>
  </div>
</template>

<script>


import { selectList } from '../../../api/business/project'
import { listInstrument } from '../../../api/business/instrument'
import { listMaterial } from '../../../api/business/material'
import { addMaterialStore } from '../../../api/business/materialStore'
import { addQualityControl } from '../../../api/business/qualityControl'

export default {
  name: 'addindoor',
  data() {
    return {
      deviceList: [],
      loading: false,
      redirect: undefined,
      registerShow: false,
      instrumentOptions: undefined,
      projectOptions: [],
      materialOptions: [],
      reagentOptions: [],
      dateOptions: [],
      form: {
        instrumentId: '',
        instrumentNo: '',
        projectId: '',
        projectName: '',
        // type: '',
        deptId: '',
        deptName: '',
        materialBatchNo: '',
        reagentBatchNo: ''
      }
    }
  },
  watch: {},
  created() {
    this.getProjectOptions()
    this.getInstrumentOptions()
    // this.getMaterialOptions();
  },
  methods: {
    onSubmit() {
      if (!this.form.instrumentId) {
        this.$message.warning('仪器编码不能为空')
        return
      }
      if (!this.form.projectId) {
        this.$message.warning('校验项目不能为空')
        return
      }
      let instrument = this.instrumentOptions.filter(x => x.id == this.form.instrumentId)[0]
      let project = this.projectOptions.filter(x => x.id == this.form.projectId)[0]
      this.form.instrumentNo = instrument.instrumentNo
      this.form.deptId = project.deptId
      this.form.deptName = project.deptName
      this.form.projectName = project.projectName
      addQualityControl(this.form).then((res) => {
        this.toBack()
      })

    },
    toBack() {
      this.reset()
      this.$emit('func', false)
    },
    getDeviceList() {
      let deviceExp = {
        name: '全自动量子点荧光免疫分析仪QD-S1200',
        deviceNo: 'NJYKD-JY-XT-000006',
        dep: '心脑血管科',
        connet: true,
        warning: false,
        lock: false,
        wait2Check: true
      }
      for (let i = 0; i < 25; i++) {
        this.deviceList.push(deviceExp)
      }
    },
    toDeviceInfo(id) {
      this.$router.push({ path: '/device/deviceInfo/index' })
    },
    getProjectOptions() {
      selectList().then(response => {
        this.projectOptions = response
      })
    },
    getInstrumentOptions() {
      listInstrument().then(response => {
        this.instrumentOptions = response.rows
      })
    },
    getMaterialOptions() {
      listMaterial().then(response => {
        // console.log("--------"+response.rows[0].type==i)
        this.materialOptions = response.rows.filter(x => x.type == 0)
        this.reagentOptions = response.rows.filter(x => x.type == 1)
      })
    },
    handleClose() {
      this.$emit('func', false)
    },
    reset() {
      let form = {
        instrumentId: '',
        instrumentNo: '',
        projectId: '',
        projectName: '',
        // type: '',
        deptId: '',
        deptName: '',
        materialBatchNo: '',
        reagentBatchNo: ''
      }
      this.form = form
    }
  }
}
</script>
